package com.rrjjg.app.core.exception;

import com.rrjjg.app.core.beans.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
public class RjControllerAdvice {

    @ExceptionHandler(RjException.class)
    public ResultData rjError(RjException e) {
        log.error("RjException is {}",e.getMessage());
        ResultData date = new ResultData();
        date.fail(e.getMessage(), e.getCode());
        return date;
    }

    @ExceptionHandler(Exception.class)
    public ResultData exce(Exception e) {
        log.error("Exception is ",e);
        ResultData date = new ResultData();
        date.fail(MsgEnum.FAIL);
        return date;
    }

}
